/**
 * Created by mola on 15-12-10.
 */

'use strict';

let PasswordSet = {
    Number : 1 << 0,
    Character : 1 << 1,
    SpecificSymbol : 1 << 2
};

PasswordSet.NumberAndChar = PasswordSet.Number | PasswordSet.Character;
PasswordSet.All = PasswordSet.Number | PasswordSet.Character | PasswordSet.SpecificSymbol;

exports.PasswordSet = PasswordSet;


const NumberSet = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const CharacterSet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                    'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                    's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                    'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                    'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];

const SpecificSymbolSet = ['!', '@', '#', '$', '%', '&'];


class PasswordConfig {
    constructor() {
        this.length = 10;
        this.passwordSet = PasswordSet.NumberAndChar;
    }

    /**
     * @returns {number|*}  length of password
     */
    getLength() { return this.length; }

    /**
     * set password length
     * @param length    length of the password
     */
    setLength(length) { this.length = length; }

    /**
     *
     * @param passwordSet PasswordSet
     */
    setPasswordSet(passwordSet) { this.passwordSet = passwordSet; }

    /**
     * password set array of config
     * @returns {Array}
     */
    getPasswordSetArray() {
        let passSet = [];
        if (this.passwordSet & PasswordSet.Number) {
            Array.prototype.push.apply(passSet, NumberSet);
        }
        if (this.passwordSet & PasswordSet.Character) {
            Array.prototype.push.apply(passSet, CharacterSet);
        }
        if (this.passwordSet & PasswordSet.SpecificSymbol) {
            Array.prototype.push.apply(passSet, SpecificSymbolSet);
        }
        return passSet;
    }
}

exports.PasswordConfig = PasswordConfig;


